﻿function v(id) {
    return $("#ContentPlaceHolder1_" + id);
}
function Lantern(div, time, direction, lanterntype) {
    var ul = div.find("ul:first");
    var li = ul.find("li");
    if (li.length == 0)
        return;
    var liSize = 0;
    div.css({ "position": "relative", "visibility": "visible", "overflow": "hidden" });
    ul.css({ "position": "relative", "left": "0", "top": "0" });
    if (direction == 0) {
        ul.css({ "width": "90000px" });
    } else {
        ul.css({ "heigth": "90000px" });
    }
    for (var i = 0; i < li.length; i++) {
        if (direction == 0) {
            liSize += $(li[i]).outerWidth();
        } else {
            liSize += $(li[i]).outerHeight();
        }
    }
    var count = 0;
    if (direction == 0) {
        count = div.outerWidth() / liSize;
    } else {
        count = div.outerHeight() / liSize;
    }

    for (var i = 0; i < count; i++) {
        ul.append(li.clone());
    }
    var movesize = 0;
    var isstop = false;
    div.hover(
		function () { isstop = true; },
		function () { isstop = false; }
	);
    setInterval(function () {
        if (isstop)
            return;
        if (lanterntype == 0) {
            if (movesize == 0 - liSize) {
                ul.css(direction == 0 ? "left" : "top", 0);
                movesize = 0;
                ul.find("li:first").appendTo(ul);
            }
            movesize--;
            ul.css(direction == 0 ? "left" : "top", movesize);
        } else {
            var firstli = ul.find("li:first");
            var firstliwidth = ul.find("li:first").outerWidth();
            ul.animate({ "left": 0 - firstliwidth }, 1000, function () {
                $(this).css("left", 0).append(firstli);
            });
        }

    }, time);
} /// <reference path="~/control/TopDoctor.ascx" />


var imgList = null, controlid = "";
function BannerImg() {
    imgList = $(controlid).find("div");
    imgCount = imgList.length;
    if (imgList != null && imgCount > 1) {
        $(imgList[1]).fadeIn(5000, function () {
            $(imgList[0]).hide();
            $(imgList[0]).appendTo($(controlid));
        });
    }
}
var imgList1 = null, controlid1 = "", actiontype = 0;
function BannerDoctor() {
    imgList1 = $(controlid1).children();
    var imgCount = imgList1.length;
    if (imgList1 != null && imgCount > 1) {
        if (actiontype == 0) {
            $(imgList1[0]).appendTo($(controlid1));
        } else {
            $(imgList1[imgCount - 1]).prependTo($(controlid1));
        }
    }
}

function InitFlash() {
    ////    var sortmenu = $("#sortmenu");
    ////    if (sortmenu.length > 0) {
    ////        var psort = sortmenu.find(".p_sort");
    ////        var subsort = sortmenu.find(".sub_sort");
    ////        $(subsort[0]).show();
    ////        psort.each(function () {
    ////            $(this).hover(function () {
    ////                var index = psort.index($(this));
    ////                for (var i = 0; i < subsort.length; i++)
    ////                    if (i == index)
    ////                        $(subsort[i]).show();
    ////                    else
    ////                        $(subsort[i]).hide();
    ////            },null);
    ////        });
    ////    }

    var topnews = $("#TopNews");
    if (topnews.length > 0) {
        var titles = topnews.find(".title:first").find("a");
        var panel = topnews.find(".info");
        titles.each(function () {
            $(this).hover(function () {
                titles.removeClass("cur_a");
                $(this).addClass("cur_a");
                var index = titles.index($(this));
                for (var i = 0; i < panel.length; i++)
                    if (i == index)
                        $(panel[i]).show();
                    else
                        $(panel[i]).hide();
            }, null);
        });
    }

    var top_about_img = $("#top_about_img");
    if (top_about_img.length > 0) {
        Lantern($("#top_about_img"), 50, 0, 0);
    }

    var top_order = $("#top_order");
    if (top_order.length > 0) {
        Lantern($("#top_order"), 50, 1, 0);
    }

    var subjectinfo = $("#SubjectInfo");
    if (subjectinfo.length > 0) {
        var subjectItems = subjectinfo.children();
        $(subjectItems[0]).addClass("currow");
        subjectItems.each(function () {
            $(this).hover(function () {
                for (var i = 0; i < subjectItems.length; i++)
                    $(subjectItems[i]).removeClass("currow");
                $(this).addClass("currow");
            }, null);
        });
    }

    var main_equipment = $("#main_equipment");
    if (main_equipment.length > 0) {
        var itemtitle = main_equipment.find(".title:first").find("a");
        var itemrow = main_equipment.find(".row");
        itemtitle.each(function () {
            $(this).hover(function () {
                itemtitle.removeClass("cur");
                $(this).addClass("cur");
                var index = itemtitle.index($(this));
                for (var i = 0; i < itemrow.length; i++)
                    if (i == index)
                        $(itemrow[i]).show();
                    else
                        $(itemrow[i]).hide();
            }, null);
        });
    }

    var main_link = $("#main_link");
    if (main_link.length > 0) {
        var itemlinktitle = main_link.find(".title:first").find("a");
        var itemlinkrow = main_link.find(".row");
        itemlinktitle.each(function () {
            $(this).hover(function () {
                itemlinktitle.removeClass("cur");
                $(this).addClass("cur");
                var index = itemlinktitle.index($(this));
                for (var i = 0; i < itemlinkrow.length; i++)
                    if (i == index)
                        $(itemlinkrow[i]).show();
                    else
                        $(itemlinkrow[i]).hide();
            }, null);
        });
    }

    var abount_ad = $("#abount_ad");
    if (abount_ad.length > 0) {
        Lantern($("#abount_ad"), 50, 0, 0);
    }

    var about_doctor = $("#about_doctor");
    if (about_doctor.length > 0) {
        var docotorList = about_doctor.find(".doctor_l:first").find("li");
        var docotorInfo = about_doctor.find(".doctor_about");
        var docotorPic = about_doctor.find(".doctor_r");
        if (docotorList.length > 0) {
            $(docotorInfo[0]).show();
            $(docotorPic[0]).show();
            docotorList.each(function () {
                $(this).hover(function () {
                    var index = docotorList.index($(this));
                    for (var i = 0; i < docotorInfo.length; i++)
                        if (i == index) {
                            $(docotorInfo[i]).show();
                            $(docotorPic[i]).show();
                        }
                        else {
                            $(docotorInfo[i]).hide();
                            $(docotorPic[i]).hide();
                        }
                }, null);
            });
        }
    }

    var innerdoctor = $("#innerdoctor");
    if (innerdoctor.length > 0) {
        Lantern($("#innerdoctor"), 50, 1, 0);
    }

    var techItem = $("#techItem");
    if (techItem.length > 0) {
        var temliList = techItem.find(".tech_title:first").find("li");
        var itemList = techItem.find(".tech_item");
        temliList.each(function () {
            $(this).hover(function () {
                var index = temliList.index($(this));
                temliList.each(function () {
                    var index1 = temliList.index($(this));
                    index1++;
                    $(this).attr("class", "techA" + index1);
                });
                for (var i = 0; i < itemList.length; i++)
                    if (i == index)
                        $(itemList[i]).show();
                    else
                        $(itemList[i]).hide();
                index++;
                $(this).attr("class", "techA" + index + " techA" + index + "_cur");
            }, null);
        });
    }


    var EquipmentImgList = $("#EquipmentImgList");
    if (EquipmentImgList.length > 0 && EquipmentImgList.find("li").length > 0)
        Lantern($("#EquipmentImgList"), 60, 0, 0);

//    var txtSearch = v("Search1_txtSearch");
//    if (txtSearch.length > 0) {
//        txtSearch.focus(function () { $(this).val(""); });
//    }

//    var topDoctor = $("#topDoctor");
//    if (topDoctor.length > 0) {
//        Lantern($("#topDoctor"), 3000, 0, 1);
//    }

//    var maindoctor = $("#maindoctor");
//    if (maindoctor.length > 0) {
//        Lantern($("#maindoctor"), 3000, 0, 1);
//    }

    var topEquipment = $("#topEquipment");
    if (topEquipment.length > 0) {
        Lantern($("#topEquipment"), 3000, 0, 1);
    }

    var webmainlist = $("#webmainlist");
    if (webmainlist.length > 0) {
        var liList = webmainlist.find("li");
        for (var i = 0; i < liList.length; i++) {
            if ((i + 1) % 2 == 0) {
                $(liList[i]).attr("class", "cur");
            }
        }
    }

    var links = $("#links");
    if (links.length > 0) {
        var liList = links.find(".links_left li");
        var items = links.find(".links_info");
        liList.each(function () {
            $(this).hover(function () {
                liList.removeClass("cur");
                $(this).addClass("cur");
                var index = liList.index($(this));
                for (var i = 0; i < items.length; i++)
                    if (i == index)
                        $(items[i]).show();
                    else
                        $(items[i]).hide();
            }, null);
        });
    }
}

function ShowPopwin() {
    var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
    $("#popwin").css("top", $(window).height() + scrollTop - 80 + "px")
}

function ShowChat() {
    window.open("http://dgt.zoosnet.net/LR/chatwin.aspx?id=DGT86297732&lng=cn");
}

$(function () {
    InitFlash();
});

function changeImageChallenge() {
    var now = new Date();
    $("#imgValidateCode").attr("src", "../ValidateCode.aspx?t" + now.getTime());
}

function DoFaq() {
    var title = $("#txtTitle").val();
    var info = $("#txtInfo").val();
    if ($.trim(title) == "") {
        alert("请输入标题！");
        $("#txtTitle").focus();
        return false;
    }
    if ($.trim(info) == "") {
        alert("请输入内容！");
        $("#txtInfo").focus();
        return false;
    }
    WebRequest({ action: "faq", title: title, info: info, sortid: $("#ddlSubSort").val(), phone: $("#txtPhone").val(), email: $("#txtEmail").val(), code: $("#txtCode").val() },
    function (data) {
        if (data.result == 0) {
            if (data.msg != null) {
                switch (data.msg) {
                    case "notitle":
                        alert("请输入问题标题！");
                        break;
                    case "noinfo":
                        alert("请输入问题描述！");
                        break;
                    case "nocode":
                        alert("请输入验证码！");
                        break;
                    case "notcode":
                        alert("验证码不正确！");
                        break;
                }
            } else {
                alert("问题提交失败，请重试！");
            }
        } else if (data.result == 1) {
            alert("问题提交成功，请等待专家的答复！");
            $("#txtTitle").val("");
            $("#txtPhone").val("");
            $("#txtEmail").val("");
            $("#txtCode").val("");
            $("#txtInfo").val("");
        }

    });
}
//请求处理
function WebRequest(parms, callFun) {
    $.ajax({ type: "post",
        url: "/RequestProcessing.aspx",
        data: parms,
        dataType: "json",
        success: function (data) {
            if (Error(data)) { if (typeof callFun == 'function') callFun(data); }
        }
    });
}
//请求失败处理
function Error(data) {
    if (data != null) {
        if (data.result == -400) {
            alert("提交失败！");
            return false;
        }
    }
    return true;
}
function BindSort() {
    if ($("#ddlSort option").length == 0) {
        for (var i = 0; i < sortjson.length; i++) {
            $("#ddlSort").append("<option value=\"" + sortjson[i].sortid + "\">" + sortjson[i].name + "</option>");
        }
    }
    $("#ddlSubSort").empty();
    for (var i = 0; i < sortjson.length; i++) {
        if (sortjson[i].sortid == $("#ddlSort").val()) {
            for (var j = 0; j < sortjson[i].subsort.length; j++) {
                $("#ddlSubSort").append("<option value=\"" + sortjson[i].subsort[j].sortid + "\">" + sortjson[i].subsort[j].name + "</option>");
            }
        }
    }
}



var FocusPic = function (BigPicID, SmallPicsID, TitleID, MemoID, width, height) {
    this.Data = [];
    this.ImgLoad = [];
    this.TimeOut = 5000;
    var isIE = navigator.appVersion.indexOf("MSIE") != -1 ? true : false;
    this.width = width;
    this.height = height;
    this.adNum = 0;
    var TimeOutObj;
    if (!FocusPic.childs) {
        FocusPic.childs = [];
    };
    this.showTime = null;
    this.showSum = 10;
    this.ID = FocusPic.childs.push(this) - 1;
    this.Add = function (BigPic, SmallPic, Title, Url, Memo) {
        var ls;
        this.Data.push([BigPic, SmallPic, Title, Url, Memo]);
        ls = this.ImgLoad.length;
        this.ImgLoad.push(new Image);
        this.ImgLoad[ls].src = BigPic
    };
    this.TimeOutBegin = function () {
        clearInterval(TimeOutObj);
        TimeOutObj = setInterval("FocusPic.childs[" + this.ID + "].next()", this.TimeOut)
    };
    this.TimeOutEnd = function () {
        clearInterval(TimeOutObj)
    };
    this.select = function (num) {
        if (num > this.Data.length - 1) {
            return
        };
        if (num == this.adNum) {
            return
        };
        this.TimeOutBegin();
        if (BigPicID) {
            if (this.$(BigPicID)) {
                var aObj = this.$(BigPicID).getElementsByTagName("a")[0];
                if (this.Data[num][2]) {
                    aObj.href = this.Data[num][2];
                    aObj.target = "_blank";
                } else {
                    aObj.href = "javascript:void(0);";
                    aObj.target = "_self";
                    // aObj.removeAttribute('target');
                }
                if (this.aImgY) {
                    this.aImgY.style.display = 'none';
                    this.aImg.style.position = "relative";
                    this.aImg.style.left = 0;
                    this.aImg.style.top = 0;
                    this.aImg.style.zIndex = 0
                };
                this.aImgY = this.$('F' + this.ID + 'BF' + this.adNum);
                this.aImg = this.$('F' + this.ID + 'BF' + num);
                clearTimeout(this.showTime);
                this.showSum = 10;
                this.showTime = setTimeout("FocusPic.childs[" + this.ID + "].show()", 50)
            }
        };
        if (TitleID) {
            if (this.$(TitleID)) {
                this.$(TitleID).innerHTML = "<a href=\"" + this.Data[num][2] + "\" target=\"_blank\">" + this.Data[num][3] + "</a>"
            }
        };
        if (MemoID) {
            if (this.$(MemoID)) {
                this.$(MemoID).innerHTML = this.Data[num][4]
            }
        };
        if (SmallPicsID) {
            if (this.$(SmallPicsID)) {
                var sImg = this.$(SmallPicsID).getElementsByTagName("span"),
				i;
                for (i = 0; i < sImg.length; i++) {
                    if (i == num || num == (i - this.Data.length)) {
                        sImg[i].className = "selected"
                    } else {
                        sImg[i].className = ""
                    }
                }
            }
        };
        this.adNum = num;
        if (this.onselect) {
            this.onselect()
        }
    };
    var absPosition = function (obj, parentObj) {
        var left = obj.offsetLeft,
		top = obj.offsetTop,
		tempObj = obj;
        while (tempObj.id != "VBody" & tempObj.id != "VHtml" & tempObj != parentObj) {
            tempObj = tempObj.offsetParent;
            left += tempObj.offsetLeft;
            top += tempObj.offsetTop
        };
        return {
            left: left,
            top: top
        }
    };
    this.show = function () {
        this.showSum--;
        this.aImgY.style.display = 'block';
        this.aImg.style.position = "absolute";
        var XY = absPosition(this.aImgY, this.$(BigPicID));
        this.aImg.style.top = XY.top + "px";
        this.aImg.style.left = XY.left + "px";
        this.aImg.style.display = 'block';
        if (isIE) {
            this.aImg.style.filter = "alpha(opacity=0)";
            this.aImg.style.filter = "alpha(opacity=" + (10 - this.showSum) * 10 + ")"
        } else {
            this.aImg.style.opacity = 0;
            this.aImg.style.opacity = (10 - this.showSum) * 0.1
        };
        if (this.showSum <= 0) {
            this.aImgY.style.display = 'none';
            this.aImg.style.position = "relative";
            this.aImg.style.left = 0;
            this.aImg.style.top = 0;
            this.aImg.style.zIndex = 0;
            this.aImgY = null
        } else {
            this.aImg.style.zIndex = 2;
            this.showTime = setTimeout("FocusPic.childs[" + this.ID + "].show()", 50)
        }
    };
    this.next = function () {
        var temp = this.adNum;
        temp++;
        if (temp >= this.Data.length) {
            temp = 0
        };
        this.select(temp)
    };
    this.MInStopEvent = function (ObjID) {
        if (ObjID) {
            if (this.$(ObjID)) {
                if (this.$(ObjID).attachEvent) {
                    this.$(ObjID).attachEvent("onmouseover", Function("FocusPic.childs[" + this.ID + "].TimeOutEnd()"));
                    this.$(ObjID).attachEvent("onmouseout", Function("FocusPic.childs[" + this.ID + "].TimeOutBegin()"))
                } else {
                    this.$(ObjID).addEventListener("mouseover", Function("FocusPic.childs[" + this.ID + "].TimeOutEnd()"), false);
                    this.$(ObjID).addEventListener("mouseout", Function("FocusPic.childs[" + this.ID + "].TimeOutBegin()"), false)
                }
            }
        }
    };
    this.begin = function () {
        this.MInStopEvent(TitleID);
        this.MInStopEvent(SmallPicsID);
        this.MInStopEvent(BigPicID);
        this.adNum = 0;
        var i, temp = "";
        if (BigPicID) {
            if (this.$(BigPicID)) {
                var aObj = this.$(BigPicID).getElementsByTagName("a")[0];
                aObj.style.zoom = 1;
                this.$(BigPicID).style.position = "relative";
                for (i = 0; i < this.Data.length; i++) {
                    temp += '<img src="' + this.Data[i][0] + '" id="F' + this.ID + 'BF' + i + '" style="display:' + (i == this.adNum ? 'block' : 'none') + '" galleryimg="no"' + (this.width ? ' width="' + this.width + '"' : '') + (this.height ? ' height="' + this.height + '"' : '') + ' alt="' + this.Data[i][3] + '" />'
                };
                if (this.Data.length) aObj.href = this.Data[0][2];
                aObj.innerHTML = temp
            }
        };
        if (SmallPicsID) {
            if (this.$(SmallPicsID)) {
                temp = "";
                for (i = 0; i < this.Data.length; i++) {

                    temp += "<span" + (this.adNum == i ? ' class="selected"' : "") + "><a href=\"javascript:void(0);\"  onmouseover=\"FocusPic.childs[" + this.ID + "].select(" + i + ")\">" + (i + 1) + "</a></span>";

                };
                this.$(SmallPicsID).innerHTML = temp
            }
        };
        if (TitleID) {
            if (this.$(TitleID)) {
                this.$(TitleID).innerHTML = "<a href=\"" + this.Data[this.adNum][2] + "\" target=\"_blank\">" + this.Data[this.adNum][3] + "</a>"
            }
        };
        if (MemoID) {
            if (this.$(MemoID)) {
                this.$(MemoID).innerHTML = this.Data[this.adNum][4]
            }
        };
        this.TimeOutBegin()
    };
    this.$ = function (objName) {
        if (document.getElementById) {
            return eval('document.getElementById("' + objName + '")')
        } else {
            return eval('document.all.' + objName)
        }
    }
};
